using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hangfire;
using Hangfire.HttpJob;
using Hangfire.Storage.SQLite;
using HangfireBasicAuthenticationFilter;
using WebApplication2.Jobs;

namespace WebApplication2
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHangfire(conf =>
            {
                conf.UseSQLiteStorage("a.db")
                    .UseHangfireHttpJob();

            });

        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseHangfireServer();
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new []{new HangfireCustomBasicAuthenticationFilter(){User = "admin",Pass = "admin"}}
            });

            RecurringJob.AddOrUpdate<UserSyncJob>(
                "user-sync",
                job=>job.Run(JobCancellationToken.Null),
                "0/10 * * * * ? ",
                TimeZoneInfo.Local);


        }
    }
}
